
import os
import xlrd
import sqlite3



class File_Read():

    def __init__(self):
        self.con = sqlite3.connect('cov19.db')
        self.cur = self.con.cursor()

    def open_dir(self,parent_path):
        if parent_path:
            item_paths = os.listdir(parent_path)
            for item_path in item_paths:
                item_path_ = os.path.join(parent_path,item_path)
                if "核心信息" in item_path_:
                    print("core")
                    self.import_core(item_path_)
                if '次密接' in item_path_:
                    print('cimije')
                    self.import_sub_contact(item_path_)
                if '密接' in item_path_ and ('次密接' not in item_path_):
                    print('mijie')
                    self.import_contact(item_path_)

    def import_core(self,xls):
        workbook = xlrd.open_workbook(xls)
        sheet = workbook.sheets()[0]
        dic = {
            'case_num':(1,2),
            'case_type':(1,7),
            'name':(3,3),
            'gender':(3,7),
            'birthday':(4,3),
            'occup':(4,5),
            'tel':(4,7),
            'id':(5,3),
            'address':(6,3),
            'company':(7,3),
            'symptom':(9,3),
            'sick_date':(9,7),
            'sample_date':(10,3),
            'ctn':(11,3),
            'ctorf':(11,7),
            'exposure':(13,7),
            'patient_name':(14,3),
            'exposure_date':(14,5),
            'exposure_time':(14,7),
            'last_contact_date':(15,3),
            'last_contact':(15,5),
            'other_exposure':(15,7),
            'detection':(16,5),

        }
        for k,v in dic.items():
            dic[k] = sheet.cell_value(*v)

        print(dic)

        dup_sql = '''select * from person  where id = "{}"
        '''.format(dic['id'])
        self.cur.execute(dup_sql)
        dup_rslt = self.cur.fetchall()
        if dup_rslt:
            sql = '''

            '''
        else:
            sql = '''

            '''

    def import_contact(self,xls):
        print(xls)

    def import_sub_contact(self,xls):
        print(xls)


test = File_Read()
test.open_dir('E:\covid19\流调表格模板')
